import BaseModel from './BaseModel'
import { post } from '@/api/ajax'
import { ProjectApi } from '@/api/apis'
import { ModelStatus } from './types'
import EnumModel from './EnumModel'
import AccountModel from "@/models/AccountModel";

class ArticleModel extends BaseModel{

  // 项目名称
  public name = ''
  // 项目状态
  status = ModelStatus.NORMAL
  // 项目描述
  public description = ''
  // 左侧enum
  enums: Array<EnumModel> = []
  // 创建人
  public createUser: AccountModel | null = null


  // 添加数据的API
  addModelApi = ProjectApi.crud
  // 添加项目的字段
  addModelField = 'name description'
  // 加载列表的API
  static loadListApi = ProjectApi.crud
  // 删除数据的API
  removeDataApi = ProjectApi.crud
  // 加载所有数据
  static loadAllApi = ProjectApi.all
  // 获取详情API
  detailApi = ProjectApi.detail



  setDataWithJson(json: {}) {
    super.setDataWithJson(json);
    this.enums = EnumModel.getModelsWithArr(this.enums)
    EnumModel.setSuperId(this._id, this.enums)
    if (this.createUser) {
      this.createUser = AccountModel.create<AccountModel>(this.createUser)
    }
  }

  /**
   * 更新项目
   */
  update<T>(data: T) {
    return post(`${ProjectApi.crud}/${this._id}`, {
      ...data
    })
  }
}

export default ArticleModel
